package com.smt.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.smt.modules.app.annotation.Login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import com.smt.common.base.BaseController;
import com.smt.modules.bus.vo.BillVo;
import com.smt.modules.bus.entity.BillEntity;
import com.smt.modules.bus.service.BillService;
import com.smt.common.utils.PageUtils;
import com.smt.common.utils.R;



/**
 * 账单表
 *
 * @author murong
 * @email 981620741@qq.com
 * @date 2018-10-17 10:06:53
 */
@RestController
@RequestMapping("app/bill")
@Api(tags = {"AppBillController"},description = "账单表",hidden = true)
public class AppBillController extends BaseController{
    @Autowired
    private BillService billService;

    /**
    * 查询当前用户账单
    * @return
    */
    @Login
    @GetMapping("/list/{classify}")
    @ApiOperation(value =  "查询当前用户账单")
    public R list(@PathVariable("classify") String classify,
                  @RequestAttribute("userId")Long userId){
        List<BillEntity> billEntities = billService.selectList(new EntityWrapper<BillEntity>()
                .eq("bus_business_id", userId)
                .eq("is_reward",2)
                .in("expenditure", classify)
                .orderBy("create_time", false));
        return R.ok("账单列表").put("list",billEntities);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "/info/{id}",notes = "根据表ID查询",response = BillVo.class)
    public R info(@PathVariable("id") Long id){
			BillEntity bill = billService.selectById(id);

        return R.ok().put("bill", bill);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "/save",notes = "添加信息保存",response = BillVo.class)
    public R save(@RequestBody BillEntity bill){
			billService.insert(bill.copyPropertiesTo(new BillEntity()));

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "/update",notes = "更新信息保存",response = BillVo.class)
    public R update(@RequestBody BillEntity bill){
			billService.updateById(bill.copyPropertiesTo(new BillEntity()));

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "/delete",notes = "批量删除",response = BillVo.class)
    public R delete(@RequestBody Long[] ids){
			billService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
